package com.lance.answer.gui.answer.gk.answer.lms.batch;

import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.google.common.base.Strings;
import com.lance.answer.gui.answer.gk.answer.lms.batch.dto.LmsWatchDTO;
import com.lance.answer.gui.answer.gk.answer.lms.batch.task.GetUserCourseInfoTask;
import com.lance.answer.gui.answer.gk.answer.lms.batch.task.LmsSaveUnVideoTask;
import com.lance.answer.gui.answer.gk.answer.lms.util.LmsUtil;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;

import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.util.List;
import java.util.concurrent.LinkedBlockingDeque;

/**
 * 获取每个人的课程信息
 */
public class GetUserCourseInfo {

    public static void main(String[] args) throws Exception {

     //   Thread.sleep(600*60*60*1);
        int sync = 4;

        LinkedBlockingDeque<LmsWatchDTO> watchQueue = new LinkedBlockingDeque<>();

     //   InputStream inputStream2 = new FileInputStream("libs//lms2022-x.user");
      //   InputStream inputStream2 = new FileInputStream("libs//lmsTeachers//all3.user");
         InputStream inputStream2 = new FileInputStream("libs//2022秋//fengx.user");
      //  InputStream inputStream2 = new FileInputStream("libs//lmsTeachers//刘俊伟.user");
        // InputStream inputStream2 = new FileInputStream("libs//lmsTeachers//李俊杰3.user");
     //   InputStream inputStream2 = new FileInputStream("libs//lmsTeachers//零散.user");
    //    InputStream inputStream2 = new FileInputStream("libs//lmsTeachers//刘俊伟.user");
     //   InputStream inputStream2 = new FileInputStream("libs//lmsTeachers//补.user");
        List<String> userString = IOUtils.readLines(inputStream2, "utf-8");

        for (String user : userString) {
            String[] strs = user.split(",");
            String userCode = strs[0];
            String pwd = strs[1];
            LmsWatchDTO lmsWatchDTO = new LmsWatchDTO();
            lmsWatchDTO.setUsername(userCode);
            lmsWatchDTO.setPassword(pwd);
//            if(!LmsUtil.getVip().contains(userCode)){
//                continue;
//            }

            File file = new File("libs//lmsCourseInfo//" + userCode + ".json");
            if(file.exists()){
                String info = IOUtils.toString(new FileInputStream(file), StandardCharsets.UTF_8);
                if (!Strings.isNullOrEmpty(info)&&info.length()>10) {
                    continue;
                }
            }


            watchQueue.add(lmsWatchDTO);
        }

        for (int i = 1; i <= sync; i++) {
            Thread answerThread = new GetUserCourseInfoTask("d:\\ynouAutoStudy\\chromedriver.exe", watchQueue);
            //log.info("加载课程ID：{} 名称：{} ", openCourseId,subjectName);
            answerThread.setName("答题线程--" + i);
            answerThread.start();
        }


    }

}
